//
//  ThumbViewController.m
//  OrderOnline
//
//  Created by YAPPA_3 on 11/28/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ThumbViewController.h"
#import "OrderOnlineViewController.h"

@implementation thumbImage
@synthesize m_imageButton;
@synthesize m_frameImage;

-(void) initVisible
{
    self.backgroundColor = [UIColor clearColor];
	[self.m_frameImage setBackgroundColor:[UIColor clearColor]];
    [self.m_imageButton setBackgroundColor:[UIColor clearColor]];
    [self.m_imageButton setUserInteractionEnabled:YES];  
}

- (void) setImage:(UIImage *)image
{
    CGSize imageSize = image.size;
	CGSize viewSize  = m_imageButton.bounds.size;
	
	float hRate = viewSize.width  / imageSize.width;
	float vRate = viewSize.height / imageSize.height;
	float ratio = ( hRate > vRate ) ? vRate : hRate;
	
	CGRect rect = CGRectMake( 0, 0, imageSize.width * ratio, imageSize.height * ratio );
	UIGraphicsBeginImageContext( rect.size );
	[image drawInRect:rect];
	
	UIImage* resizeImage = UIGraphicsGetImageFromCurrentImageContext();
	UIImageView* image_view = [[[UIImageView alloc] initWithImage:resizeImage] autorelease];
	image_view.frame = getAspectRect( rect, m_imageButton.frame);
	[self addSubview:image_view];
	UIGraphicsEndImageContext();	
	[m_imageButton setUserInteractionEnabled:YES];
}

- (void) setFrameForImage: (UIImage*)image
{
	CGSize imageSize = image.size;
	CGSize viewSize  = m_frameImage.bounds.size;	
	float hRate = viewSize.width  / imageSize.width;
	float vRate = viewSize.height / imageSize.height;
	float ratio = ( hRate > vRate ) ? vRate : hRate;	
	CGRect rect = CGRectMake( 0, 0, imageSize.width * ratio, imageSize.height * ratio );
	UIGraphicsBeginImageContext( rect.size );
	[image drawInRect:rect];
//	UIImage* resizeImage = UIGraphicsGetImageFromCurrentImageContext();
	m_frameImage.frame = getAspectRect( rect, m_frameImage.frame);
	
	m_frameImage.contentMode =  UIViewContentModeScaleAspectFit;
	m_frameImage.alpha = 1.0f;
	UIGraphicsEndImageContext();
}
- (void) setImageToButton:(UIImage *)image
{
	CGSize imageSize = image.size;
	CGSize viewSize  = m_imageButton.bounds.size;
	
	float hRate = viewSize.width  / imageSize.width;
	float vRate = viewSize.height / imageSize.height;
	float ratio = ( hRate > vRate ) ? vRate : hRate;
	
	CGRect rect = CGRectMake( 0, 0, imageSize.width * ratio, imageSize.height * ratio );
	UIGraphicsBeginImageContext( rect.size );
	[image drawInRect:rect];
	
	UIImage* resizeImage = UIGraphicsGetImageFromCurrentImageContext();
	[m_imageButton setImage:resizeImage forState:UIControlStateNormal];
	UIGraphicsEndImageContext();	
	
	m_imageButton.contentMode = UIViewContentModeScaleAspectFit;
	m_imageButton.alpha = 1.0f;
    [m_imageButton setUserInteractionEnabled:YES];	
	
}

- (void) dealloc
{
    [super dealloc];
    [m_imageButton release];   
	[m_frameImage release];
}

@end

@implementation thumbImageIcon
@synthesize m_thumbImage;

- (void) dealloc
{
    [super dealloc];
    [m_thumbImage release];   
}

@end


@implementation ThumbViewController
@synthesize m_food;
@synthesize m_pageNo;

- (void) dealloc
{
    [super dealloc];
     
}
- (void) tapImage: (id) sender
{
	[[OrderOnlineViewController Shared] changeReadView:YES];
	[[OrderOnlineViewController Shared] changePage:m_pageNo];
}

@end
